<script lang="ts">
import type { OnLaunchOptions } from '@/utils';
import { checkUrl, clientWatcher, mpUpdate } from '@/utils';
import {getTimDataApi} from "@/api/user";
import Tim from "@/utils/ImSocket";

interface RouterItem {
  pagePath: string;
  icon: string;
  iconActive: string;
  text: string;
}

type ClientType = 'customer' | 'enterprise' | '';
type TabbarConfig = Record<ClientType, RouterItem[]>;

export default {
  globalData: {
    tabbarHeight: 100,
    // TODO 后续根据后端定义
    // 双端 customer用户端、enterprise企业端、''教师端不显示
    clientType: '' as ClientType,
    tabbarConfig: {
      customer: [
        {
          pagePath: '/pages/tab/home/index',
          icon: './images/home.png',
          iconActive: './images/home-a.png',
          text: '首页',
        },
        {
          pagePath: '/pages/tab/list/index',
          icon: './images/findJob.png',
          iconActive: './images/findJob-a.png',
          text: '找工作',
        },
        {
          pagePath: '/pages/tab/message/index',
          icon: './images/message.png',
          iconActive: './images/message-a.png',
          text: '消息',
        },
        {
          pagePath: '/pages/tab/user/index',
          icon: './images/user.png',
          iconActive: './images/user-a.png',
          text: '我的',
        },
      ],
      enterprise: [
        {
          pagePath: '/pages/tab/home/index',
          icon: './images/home.png',
          iconActive: './images/home-a.png',
          text: '首页',
        },
        {
          pagePath: '/pages/tab/list/index',
          icon: './images/recruitment.png',
          iconActive: './images/recruitment-a.png',
          text: '招人',
        },
        {
          pagePath: '/pages/tab/message/index',
          icon: './images/message.png',
          iconActive: './images/message-a.png',
          text: '消息',
        },
        {
          pagePath: '/pages/tab/user/index',
          icon: './images/user.png',
          iconActive: './images/user-a.png',
          text: '我的',
        },
      ],
    } as TabbarConfig,
  },
  onLaunch(options: OnLaunchOptions) {
    // #ifdef MP-WEIXIN
    mpUpdate();
    checkUrl(options);
    clientWatcher();
    // #endif
  },
  onShow() {
    console.log('App Show');
    if( uni.getStorageSync('user')) {
      let user_id = uni.getStorageSync('user') ? JSON.parse(uni.getStorageSync('user')).info.id : ''
      getTimDataApi({
        user_id: user_id
      }).then(res => {
        Tim.CreateTim(res)
      }).catch(err => {
        console.log('980808--8-', err)
      })
    }
  },
  onHide() {
    Tim.LoginOut()
    console.log('App Hide');
  },
  onReady() {
    console.log('onReady');
  },
};
</script>

<style lang="scss">
/* 每个页面公共css */
@import 'uview-plus/index.scss';
@import '@/static/styles/common.scss';
</style>
